package com.ict.fly.service.impl;

import com.ict.fly.dao.FAirplaneMapper;
import com.ict.fly.dao.FSeattypeMapper;
import com.ict.fly.domain.entity.FAirplane;
import com.ict.fly.domain.entity.FSeattype;
import com.ict.fly.domain.input.AddPlane;
import com.ict.fly.domain.input.PlaneEntity;
import com.ict.fly.domain.result.Result;
import com.ict.fly.service.AirplaneService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AirplaneService_imp implements AirplaneService {

    @Resource
    private FAirplaneMapper fAirplaneMapper;


    //新增航班
    @Override
    public Result addAirplane(AddPlane addPlane) {
        Result result = new Result();
        FAirplane f = fAirplaneMapper.findByName(addPlane.getPlane_name());
        if (f != null) {
            result.setStatus(-1);
            result.setMsg("此航班已存在");
            return result;
        }
        FAirplane fAirplane = new FAirplane();
        fAirplane.setPlaneType(addPlane.getPlane_type());
        fAirplane.setPlaneSeat(addPlane.getPlane_seat());
        fAirplane.setPlaneName(addPlane.getPlane_name());
        fAirplane.setPlaneLocationx(addPlane.getPlane_lx());
        fAirplane.setPlaneLocationy(addPlane.getPlane_ly());
        fAirplane.setPlaneUse(0);//默认新增航班可用
        fAirplaneMapper.insert(fAirplane);
        result.setStatus(0);
        result.setMsg("航班新增成功");
        result.setData(fAirplane);
        return result;
    }



    //查询所有航班
    @Override
    public Result selAll() {
        Result result = new Result();
        List<FAirplane> lists = fAirplaneMapper.selectAll();
        if (lists == null) {
            result.setStatus(-1);
            result.setMsg("暂无航班记录");
            return result;
        }
        result.setStatus(0);
        result.setMsg("航班查询成功");
        result.setData(lists);
        return result;
    }
}
